package com.bawei.module_notice.ui

import com.bawei.lib_common.base.BaseResponse
import com.bawei.module_notice.http.AnnouncementApi
import com.bawei.module_notice.http.AnnouncementModule
import com.bawei.module_notice.model.NoticeModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class NoticeRepository @Inject constructor(

    @AnnouncementModule.CommonMainApi // 替换为公告模块的限定符
    private val api: AnnouncementApi
) {
    /**
     * 获取公告列表
     */
    fun fetchAnnouncements(
        page: Int = 0,
        size: Int = 10
    ) = flow {
        val response = api.getAnnouncements(page, size) // 调用API
        emit(response) // 发射响应结果
    }.flowOn(Dispatchers.IO) // 切IO线程

    fun getNoticeDetail(noticeId: Int): Flow<BaseResponse<NoticeModel>> = flow {
        val response = api.getNoticeDetail(noticeId) // 执行 suspend 接口
        emit(response) // 发射结果
    }.flowOn(Dispatchers.IO) // 切 IO 线程

}